// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Service Management API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_api_servicemanagement_v1::client::ServiceManager;
/// let client = ServiceManager::builder().build().await?;
/// // use `client` to make requests to the Service Management API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// [Google Service Management
/// API](https://cloud.google.com/service-infrastructure/docs/overview)
///
/// # Configuration
///
/// To configure `ServiceManager` use the `with_*` methods in the type returned
/// by [builder()][ServiceManager::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://servicemanagement.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::service_manager::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::service_manager::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ServiceManager` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ServiceManager` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ServiceManager {
    inner: std::sync::Arc<dyn super::stub::dynamic::ServiceManager>,
}

impl ServiceManager {
    /// Returns a builder for [ServiceManager].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_api_servicemanagement_v1::client::ServiceManager;
    /// let client = ServiceManager::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::service_manager::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::service_manager::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ServiceManager + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ServiceManager>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ServiceManager> {
        super::transport::ServiceManager::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ServiceManager> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ServiceManager::new)
    }

    /// Lists managed services.
    ///
    /// Returns all public services. For authenticated users, also returns all
    /// services the calling user has "servicemanagement.services.get" permission
    /// for.
    pub fn list_services(&self) -> super::builder::service_manager::ListServices {
        super::builder::service_manager::ListServices::new(self.inner.clone())
    }

    /// Gets a managed service. Authentication is required unless the service is
    /// public.
    pub fn get_service(&self) -> super::builder::service_manager::GetService {
        super::builder::service_manager::GetService::new(self.inner.clone())
    }

    /// Creates a new managed service.
    ///
    /// A managed service is immutable, and is subject to mandatory 30-day
    /// data retention. You cannot move a service or recreate it within 30 days
    /// after deletion.
    ///
    /// One producer project can own no more than 500 services. For security and
    /// reliability purposes, a production service should be hosted in a
    /// dedicated producer project.
    ///
    /// Operation<response: ManagedService>
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_service(&self) -> super::builder::service_manager::CreateService {
        super::builder::service_manager::CreateService::new(self.inner.clone())
    }

    /// Deletes a managed service. This method will change the service to the
    /// `Soft-Delete` state for 30 days. Within this period, service producers may
    /// call
    /// [UndeleteService][google.api.servicemanagement.v1.ServiceManager.UndeleteService]
    /// to restore the service. After 30 days, the service will be permanently
    /// deleted.
    ///
    /// Operation<response: google.protobuf.Empty>
    ///
    /// [google.api.servicemanagement.v1.ServiceManager.UndeleteService]: crate::client::ServiceManager::undelete_service
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_service(&self) -> super::builder::service_manager::DeleteService {
        super::builder::service_manager::DeleteService::new(self.inner.clone())
    }

    /// Revives a previously deleted managed service. The method restores the
    /// service using the configuration at the time the service was deleted.
    /// The target service must exist and must have been deleted within the
    /// last 30 days.
    ///
    /// Operation<response: UndeleteServiceResponse>
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn undelete_service(&self) -> super::builder::service_manager::UndeleteService {
        super::builder::service_manager::UndeleteService::new(self.inner.clone())
    }

    /// Lists the history of the service configuration for a managed service,
    /// from the newest to the oldest.
    pub fn list_service_configs(&self) -> super::builder::service_manager::ListServiceConfigs {
        super::builder::service_manager::ListServiceConfigs::new(self.inner.clone())
    }

    /// Gets a service configuration (version) for a managed service.
    pub fn get_service_config(&self) -> super::builder::service_manager::GetServiceConfig {
        super::builder::service_manager::GetServiceConfig::new(self.inner.clone())
    }

    /// Creates a new service configuration (version) for a managed service.
    /// This method only stores the service configuration. To roll out the service
    /// configuration to backend systems please call
    /// [CreateServiceRollout][google.api.servicemanagement.v1.ServiceManager.CreateServiceRollout].
    ///
    /// Only the 100 most recent service configurations and ones referenced by
    /// existing rollouts are kept for each service. The rest will be deleted
    /// eventually.
    ///
    /// [google.api.servicemanagement.v1.ServiceManager.CreateServiceRollout]: crate::client::ServiceManager::create_service_rollout
    pub fn create_service_config(&self) -> super::builder::service_manager::CreateServiceConfig {
        super::builder::service_manager::CreateServiceConfig::new(self.inner.clone())
    }

    /// Creates a new service configuration (version) for a managed service based
    /// on
    /// user-supplied configuration source files (for example: OpenAPI
    /// Specification). This method stores the source configurations as well as the
    /// generated service configuration. To rollout the service configuration to
    /// other services,
    /// please call
    /// [CreateServiceRollout][google.api.servicemanagement.v1.ServiceManager.CreateServiceRollout].
    ///
    /// Only the 100 most recent configuration sources and ones referenced by
    /// existing service configurtions are kept for each service. The rest will be
    /// deleted eventually.
    ///
    /// Operation<response: SubmitConfigSourceResponse>
    ///
    /// [google.api.servicemanagement.v1.ServiceManager.CreateServiceRollout]: crate::client::ServiceManager::create_service_rollout
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn submit_config_source(&self) -> super::builder::service_manager::SubmitConfigSource {
        super::builder::service_manager::SubmitConfigSource::new(self.inner.clone())
    }

    /// Lists the history of the service configuration rollouts for a managed
    /// service, from the newest to the oldest.
    pub fn list_service_rollouts(&self) -> super::builder::service_manager::ListServiceRollouts {
        super::builder::service_manager::ListServiceRollouts::new(self.inner.clone())
    }

    /// Gets a service configuration
    /// [rollout][google.api.servicemanagement.v1.Rollout].
    ///
    /// [google.api.servicemanagement.v1.Rollout]: crate::model::Rollout
    pub fn get_service_rollout(&self) -> super::builder::service_manager::GetServiceRollout {
        super::builder::service_manager::GetServiceRollout::new(self.inner.clone())
    }

    /// Creates a new service configuration rollout. Based on rollout, the
    /// Google Service Management will roll out the service configurations to
    /// different backend services. For example, the logging configuration will be
    /// pushed to Google Cloud Logging.
    ///
    /// Please note that any previous pending and running Rollouts and associated
    /// Operations will be automatically cancelled so that the latest Rollout will
    /// not be blocked by previous Rollouts.
    ///
    /// Only the 100 most recent (in any state) and the last 10 successful (if not
    /// already part of the set of 100 most recent) rollouts are kept for each
    /// service. The rest will be deleted eventually.
    ///
    /// Operation<response: Rollout>
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_service_rollout(&self) -> super::builder::service_manager::CreateServiceRollout {
        super::builder::service_manager::CreateServiceRollout::new(self.inner.clone())
    }

    /// Generates and returns a report (errors, warnings and changes from
    /// existing configurations) associated with
    /// GenerateConfigReportRequest.new_value
    ///
    /// If GenerateConfigReportRequest.old_value is specified,
    /// GenerateConfigReportRequest will contain a single ChangeReport based on the
    /// comparison between GenerateConfigReportRequest.new_value and
    /// GenerateConfigReportRequest.old_value.
    /// If GenerateConfigReportRequest.old_value is not specified, this method
    /// will compare GenerateConfigReportRequest.new_value with the last pushed
    /// service configuration.
    pub fn generate_config_report(&self) -> super::builder::service_manager::GenerateConfigReport {
        super::builder::service_manager::GenerateConfigReport::new(self.inner.clone())
    }

    /// Sets the access control policy on the specified resource. Replaces
    /// any existing policy.
    ///
    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
    /// errors.
    pub fn set_iam_policy(&self) -> super::builder::service_manager::SetIamPolicy {
        super::builder::service_manager::SetIamPolicy::new(self.inner.clone())
    }

    /// Gets the access control policy for a resource. Returns an empty policy
    /// if the resource exists and does not have a policy set.
    pub fn get_iam_policy(&self) -> super::builder::service_manager::GetIamPolicy {
        super::builder::service_manager::GetIamPolicy::new(self.inner.clone())
    }

    /// Returns permissions that a caller has on the specified resource. If the
    /// resource does not exist, this will return an empty set of
    /// permissions, not a `NOT_FOUND` error.
    ///
    /// Note: This operation is designed to be used for building
    /// permission-aware UIs and command-line tools, not for authorization
    /// checking. This operation may "fail open" without warning.
    pub fn test_iam_permissions(&self) -> super::builder::service_manager::TestIamPermissions {
        super::builder::service_manager::TestIamPermissions::new(self.inner.clone())
    }

    /// Lists service operations that match the specified filter in the request.
    pub fn list_operations(&self) -> super::builder::service_manager::ListOperations {
        super::builder::service_manager::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::service_manager::GetOperation {
        super::builder::service_manager::GetOperation::new(self.inner.clone())
    }
}
